/*
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __X_BRUTE__
#define __X_BRUTE__

#define MAX_CMP_VALUES 5 // an arbitrary limit
#define MAXTICCMDS 4 // what a confusing name

// use is intentionally skipped
enum {
    LINE_CROSS,
    RNG_INDEX,
    DAMAGE,
    X_POS,
    Y_POS,
    Z_POS,
    X_MOM,
    Y_MOM,
    SPEED, // double
    MAXVALUES
};

enum {
    CMP_NONE,
    CMP_EQU, // ==
    CMP_NEQ, // !=
    CMP_GEQ, // >=
    CMP_GTR, // >
    CMP_LEQ, // <=
    CMP_LSS, // <
    MAXCHECKS
};

struct brutecmd {
    int tic;
    unsigned char player;
    signed char *forwardmove;
    signed char *sidemove;
    signed short *angleturn;
    unsigned char *buttons;
    unsigned short forwardmove_len;
    unsigned short sidemove_len;
    unsigned short angleturn_len;
    unsigned short buttons_len;
};

struct brutecheck {
    int tic;
    unsigned char player;
    unsigned char cmd_offset[MAXTICCMDS]; // brutecmd.x
    unsigned char plr_offset[MAXTICCMDS]; // ticcmd_t.x
    unsigned char len_offset[MAXTICCMDS]; // brutecmd.*_len
    unsigned char type[MAXTICCMDS]; // 0 is signed char, 1 is signed short
    unsigned char usecheck; // 0 or 1
    unsigned char cmp[MAXVALUES][MAX_CMP_VALUES];
    int values[SPEED][MAX_CMP_VALUES];
    double values_d[MAXVALUES - SPEED][MAX_CMP_VALUES];
};

// returns 1 on success
int x_startBrute(struct brutecmd tics[], int len, struct brutecheck check);
int x_doBrute(struct brutecmd cmds[], int pos, int len, struct brutecheck ch);

#endif
